"Truncate the description of keys to this length. Also adds
\"..\".")
(defvar which-key-key-replacement-alist
- '((">". "") ("<" . "") ("left" ."←") ("right" . "→"))
- "The strings in the car of each cons cell are replaced with the
+ '(("<\\(\\(C-\\|M-\\)*.+\\)>" . "\\1") ("\\(left\\)" ."←")
+ ("\\(right\\)" . "→"))
+ "The strings in the car of each cons cell are replaced with the
strings in the cdr for each key.")
-(defvar which-key-general-replacement-alist
+(defvar which-key-description-replacement-alist
'(("Prefix Command" . "prefix"))
"See `which-key-key-replacement-alist'. This is a list of cons
-cells for replacing any text, keys and descriptions.")
+cells for replacing descriptions.")
(defvar which-key-buffer-name "*which-key*"
"Name of which-key buffer.")
(defvar which-key-popup-type 'minibuffer
key-match desc-match unformatted formatted)
(with-temp-buffer
(describe-buffer-bindings buffer key)
- (which-key/replace-strings-from-alist which-key-general-replacement-alist)
(goto-char (point-max)) ; want to put last keys in first
(while (re-search-backward
(format "^%s \\([^ \t]+\\)[ \t]+\\(\\(?:[^ \t\n]+ ?\\)+\\)$"
key-str-qt)
nil t)
- (setq key-match (s-replace-all
- which-key-key-replacement-alist (match-string 1))
+ (setq key-match (match-string 1)
desc-match (match-string 2)
max-len-key (max max-len-key (length key-match))
max-len-desc (max max-len-desc (length desc-match)))
(goto-char (point-min)))))
(cons act-height act-width)))
-(defun which-key/replace-strings-from-alist (replacements)
+(defun which-key/perform-replacements (key-desc-cons-list key-reps desc-reps &optional literal)
"Find and replace text in buffer according to REPLACEMENTS,
which is an alist where the car of each element is the text to
replace and the cdr is the replacement text."
- (dolist (rep replacements)
- (save-excursion
- (goto-char (point-min))
- (while (or (search-forward (car rep) nil t))
- (replace-match (cdr rep) t t)))))
+ (mapcar
+ (lambda (el)
+ (let ((key (car el)) (desc (cdr el)))
+ (dolist (key-rep key-reps)
+ (setq key
+ (if (string-match (car key-rep) key)
+ (replace-match (cdr key-rep) t literal key)
+ key)))
+ (dolist (desc-rep desc-reps)
+ (setq desc
+ (if (string-match (car desc-rep) desc)
+ (replace-match (cdr desc-rep) t literal desc)
+ desc)))
+ (cons key desc))) key-desc-cons-list))
(defsubst which-key/truncate-description (desc)
"Truncate DESC description to `which-key-max-description-length'."
strings (including text properties), and pad with spaces so that
all are a uniform length. MAX-LEN-KEY and MAX-LEN-DESC are the
longest key and description in the buffer, respectively."
+ (setq unformatted (which-key/perform-replacements
+ unformatted which-key-key-replacement-alist
+ which-key-description-replacement-alist nil))
(mapcar
(lambda (key-desc-cons)
(let* ((key (car key-desc-cons))